from Constants import CHUNK_SIZE, ATLAS_UNIT_LENGTH, ATLAS_UNIT
import math


def get_chunk_pos_by_world_pos(world_pos):
    """获取区块在世界坐标系中的位置"""
    try:
        return math.floor(world_pos[0] // CHUNK_SIZE) * CHUNK_SIZE, math.floor(world_pos[2] // CHUNK_SIZE) * CHUNK_SIZE
    except ValueError:
        print("value error!")
        return None


def float_position_to_block(world_pos):
    return math.floor(world_pos[0]), math.floor(world_pos[1]), math.floor(world_pos[2])


def get_texture_list(texture_id):
    """获取纹理坐标"""
    line = texture_id % ATLAS_UNIT_LENGTH
    row = texture_id // ATLAS_UNIT_LENGTH
    res = [(line * ATLAS_UNIT, row * ATLAS_UNIT),
           ((line + 1) * ATLAS_UNIT, row * ATLAS_UNIT),
           ((line + 1) * ATLAS_UNIT, (row + 1) * ATLAS_UNIT),
           (line * ATLAS_UNIT, (row + 1) * ATLAS_UNIT)]
    return res


if __name__ == '__main__':
    print(get_texture_list(2))
